﻿namespace Cubezicles.NeedObjects
{
    using System;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;

    // Stub class to represent objects that fulfill employee needs
    // "Clickable" means they are able to be chosen, and are highlighted when chosen
    public class NeedObject : ClickableGameComponent
    {
        public Vector3 InFrontOf { get; set; }

        public Employee CurrentUser { get; private set; }
        public Employee NextUser { get; private set; }

        // ugh, better name for this maybe?
        public MoodLevels ObjectMoodDecayRates { get; private set; }

        public SoundEffect ObjectSound { get; private set; }
        public bool IsPlaying { get; private set; }

        private readonly String soundEffectName = "";

        #region NeedObjectFileNames
        //SoundEffect flush;
        protected const String FlushSound = "Sounds/toiletflush";
        protected const String BathroomModelName = "Models/NeedObjects/bathrooms"; //***** todo fix bathroom model - no ceiling

        //SoundEffect pinball;
        protected const String PinballSound = "Sounds/pinball";
        protected const String PinballModelName = "Models/NeedObjects/pinballMachine";

        //SoundEffect snackVending;
        protected const String SnackVendingSound = "Sounds/snackvending";
        protected const String VendingMachineModelName = "Models/NeedObjects/vendingMachine";

        //SoundEffect drinkVending;
        protected const String DrinkVendingSound = "Sounds/sodavending";
        protected const String DrinkMachineModelName = "Models/NeedObjects/drinkMachine";
        //SoundEffect typing;
        protected const String TypingSound = "Sounds/typing";

        #endregion


        public NeedObject(Game1 game, Vector3 pos, string modelName, String soundEffectFileName)
            : base(game, pos, modelName)
        {
            InFrontOf = pos + new Vector3(5f, 0f, 0f);
            soundEffectName = soundEffectFileName;
        }

        protected override void LoadContent()
        {
            ObjectSound = Game.Content.Load<SoundEffect>(soundEffectName);
            base.LoadContent();
        }

        // send the user currently using this thingy back to the cube
        public void ClearUser()
        {
            //CurrentUser.Position = CurrentUser.cubicle.Position; //+ Employee.CubeOffset;
            CurrentUser.changeInState = true;
            CurrentUser.CurrentState = NeedsManager.State.Working; // Employee.State.Working
            CurrentUser = null;
            NextUser = null;
            IsPlaying = false;
        }

        public void SetUser(Employee emp)
        {
            // If the thingy is not in use, ...
            if (CurrentUser == null) //&& NextUser == null)
            {
                CurrentUser = emp;
            }
        }

        public override void Update(GameTime gameTime)
        {
            if (CurrentUser !=null && CurrentUser.ReachedDestination() && !IsPlaying)
            {
                ObjectSound.Play();
                IsPlaying = true; // this should really be set using the duration or something...
            }
            
            base.Update(gameTime);
        }
    }
}